<template>
	<div id="app">
		<login-ing v-if="admin===false"></login-ing>
		<login v-else-if="admin===null"></login>
		<router-view v-else />
	</div>
</template>

<script>
	import loginIng from '@/views/Login/logining.vue'
	import login from '@/views/Login/login.vue'
	import {getAllTags} from '@/api/tag.js'
	import {$get,$post} from '@/puigins/request.js'
	export default {
		created() {
			//自动登录
			this.autoLogin()
		},
		mounted() {
			//初始化大小监听
			this.initSize()
			window.addEventListener("resize", this.initSize)
		},
		methods: {
			initSize() {
				//小于一定值，在html标签上添加mobile标识
				if (window.innerWidth < 860) {
					document.documentElement.setAttribute("mobile", "")
				} else {
					document.documentElement.removeAttribute("mobile")
				}
			},
			autoLogin(){
				$get("/manage/admin/autoLogin").then(res=>{
					console.log("res",res)
					if(res.code==200){
						this.$store.commit("set_admin",res.data)
					}else{
						this.$store.commit("set_admin",null)
					}
				}).catch(e=>{
					console.error(e)
					this.$message.error("连接服务器失败,3秒后重试")
					setTimeout(()=>{
						this.autoLogin()
					},3000)
				})
			}
		},
		computed: {
			admin() {
				return this.$store.state.admin
			}
		},
		components: {
			loginIng,
			login
		}
	}
</script>

<style lang="scss">
	* {
		margin: 0;
		padding: 0;
		text-decoration: none;
		box-sizing: border-box;
	}

	html,
	body,
	#app {
		overflow: hidden;
		height: 100%;
	}

	.jcenter {
		display: flex !important;
		align-items: center !important;
		justify-content: center !important;
	}
	.acenter{
		text-align: center !important;
	}

	.usn {
		* {
			user-select: none;
		}
	}
	.query-box {
		padding-top: 10px;
		padding-left: 20px;
	}
</style>
